package com.wei.web.demo.biz.service;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.wei.client.basic.service.IBasicService;
import com.wei.web.client.biz.model.dto.BizDTO;
import com.wei.web.client.biz.model.req.CreateBizCmd;
import com.wei.web.client.biz.service.IBizService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author buhuan.wang
 * @since 2022/12/21
 */
@DubboService
public class BizService implements IBizService {
    public static final String CREATE_SENTINEL_RESOURCE = "BizServiceCreate";

    @DubboReference
    private IBasicService basicService;

    @Override
    public BizDTO create(CreateBizCmd cmd) {
        BizDTO bizDTO = null;
        try (Entry entry = SphU.entry(CREATE_SENTINEL_RESOURCE)) {
            bizDTO = BizDTO.builder().id("1").name("Tom").build();
        } catch (BlockException blockException) {
            bizDTO = null;
        }
        return bizDTO;
    }
}
